Micron Document




Object-oriented programming
part 15/57 · 94.0 KB total
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Information hiding is organizing code so that it is accessible only to the code that needs it; not to the rest of the codebase. The internal details of an object are hidden from the outside code, allowing for changing how an object works without affecting its interface and therefore other code. Hiding information helps prevent problems when changing the code.cite-ref-35[35] Objects act as a barrier between their internal workings and external, consuming code. Consuming code can only interact with an object via its public members.

Some programming languages, like Java, provide information hiding via visibility key words (private and public).cite-ref-footnotebloch201873-77chapter-4-item15-minimize-the-accessibility-of-classes-and-members-36-0[36] Some languages don't provide a visibility feature, but developers might follow a convention such as starting a private member name with an underscore. Intermediate levels of access also exist, such as Java's protected keyword, (which allows access from the same class and its subclasses, but not objects of a different class), and the internal keyword in C#, Swift, and Kotlin, which restricts access to files within the same module.cite-ref-37[37]

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────